<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no"/>
    <title>用户注册</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css"/>
    <style>
        body {
            background-color: #F3F3F3;
        }

        .aui-content {
            margin-top: 3px;
        }

        .aui-btn-block {
            margin-top: 5px;
            padding: 8px 0;
            font-size: 18px;
        }

        .aui-input-row {
            /*margin: 0 18px;*/
        }

        .aui-input-row {
            border-top: 0px solid #c8c7cc;
        }

        .aui-input-row:first-child:after {
            border-top: 0px solid #c8c7cc;
        }

        .aui-btn-row:after {
            border-bottom: 0px solid #c8c7cc;
        }

        .border_r {
            height: 100%;
            border-right: 1px solid #EBEBEB;
            padding: 0 15px !important;
        }

        .br {
            padding-top: 10px;
        }
    </style>
</head>
<body>
<div class="br"></div>
<div class="aui-content">
    <div id="member">
        <div class="aui-form">
            <div class="aui-input-row">
                <span class="aui-input-addon border_r">手　机　号</span>
                <input type="tel" id="memberMobile"  value=""  class="aui-input" placeholder="请输入手机号"/>
            </div>
            <div class="aui-input-row">
                <span class="aui-input-addon border_r">推荐手机号</span>
                <input type="tel" id="memberUpMobile" value=""  class="aui-input" placeholder="请输入推荐人手机号"/>
            </div>
            <div class="aui-input-row">
                <span class="aui-input-addon border_r">验　证　码</span>
                <input type="number" id="memberVerify" class="aui-input" placeholder="请输入验证码"/>
                <span class="aui-input-addon">
						<div class="aui-btn" id="memberSendVerify" onclick="getVerify('member')">
                            获取验证码
                        </div> </span>
            </div>
            <div class="aui-input-row">
                <span class="aui-input-addon border_r">密　　　码</span>
                <input type="password"  id="memberPassword" class="aui-input" placeholder="请输入密码"/>
            </div>

        </div>
        <div class="aui-btn-row">
            <div class="aui-btn aui-btn-info aui-btn-block" tapmode onclick="writeData('member');">
                提交
            </div>
        </div>
    </div>
    <div id="supplier" class="dispalyNone">
        <div class="aui-form">
            <div class="aui-input-row">
                <span class="aui-input-addon border_r">姓　　名</span>
                <input type="text" id="supplierName"  class="aui-input" placeholder="请输入姓名"/>
            </div>
            <div class="aui-input-row">
                <span class="aui-input-addon border_r">手机号码</span>
                <input type="tel" id="supplierMobile"   class="aui-input" placeholder="请输入手机号"/>
            </div>
            <div class="aui-input-row">
                <span class="aui-input-addon border_r">店铺名称</span>
                <input type="text" id="shopName"   class="aui-input" placeholder="请输入店铺名称"/>
            </div>
            <div class="aui-input-row">
                <span class="aui-input-addon border_r">详细地址</span>
                <input type="text" id="address"   class="aui-input" placeholder="请输入详细地址"/>
            </div>
            <div class="aui-input-row">
                <span class="aui-input-addon border_r">　验证码</span>
                <input type="number" id="supplierVerify" class="aui-input" placeholder="请输入验证码"/>
                <span class="aui-input-addon">
						<div class="aui-btn" id="supplierSendVerify" onclick="getVerify('supplier')">
                            获取验证码
                        </div> </span>
            </div>
            <div class="aui-input-row">
                <span class="aui-input-addon border_r">密　　码</span>
                <input type="password" value="" id="supplierPassword" class="aui-input" placeholder="请输入密码"/>
            </div>

        </div>
        <div class="aui-btn-row">
            <div class="aui-btn aui-btn-info aui-btn-block" tapmode onclick="writeData('supplier');">
                提交
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/jquery-1.11.3.js"></script>
<script type="text/javascript">
    var isinerval, times;
    var mobile = "", vrify = "", password = "", address = "", shopName = "", supplierName = "", memberUpMobile, postUrl = "",registerMobile="";
    apiready = function () {
        registerMobile=api.pageParam.registerMobile;
        if(registerMobile!=""){
            $("#memberUpMobile").val(registerMobile);
        }
        api.parseTapmode();
    }


    function closeWin() {
        api.closeWin();
    }
    function writeData(type) {
        mobile = $api.val($api.byId(type + 'Mobile'));
        vrify = $api.val($api.byId(type + 'Verify'));
        password = $api.val($api.byId(type + 'Password'));
        if (type == "supplier") {
            address = $api.val($api.byId('address'));
            shopName = $api.val($api.byId('shopName'));
            supplierName = $api.val($api.byId('supplierName'));
            if (address == "" || shopName == "" || supplierName == "") {
                api.toast({
                    msg: "请输入完整信息"
                })
                return false;
            }
        } else {
            memberUpMobile = $api.val($api.byId("memberUpMobile"));
            if (memberUpMobile == "") {
                api.toast({
                    msg: "请输入完整信息"
                })
                return false;
            }
        }

        var data = {};
        data['mobile'] = mobile;
        data['password'] = password;
        data['verifycode'] = vrify;
        if (type == "supplier") {
            data['name'] = supplierName;
            data['supplier_name'] = shopName;
            data['address'] = address;
            postUrl = 'account/register_supplier';
        } else {
            data["referer_mobile"] = memberUpMobile;
            postUrl = 'account/register_user';
        }
//        alert(JSON.stringify(data))
        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '正在注册...',
            text: '',
            modal: true
        });
//        alert(JSON.stringify(data))
        ajaxRequest(postUrl, 'post', data, function (ret, err) {
            api.toast({
                msg:"注册成功"
            })
            $api.clearStorage();
            $api.setStorage('user_id', '' + ret.data.user_id + '');
            $api.setStorage("user_password", '' + ret.data.password + '');
            $api.setStorage("member_type", '' + ret.data.account_type + '');
            $api.setStorage('user_name', '' + ret.data.user_name + '');

//            $api.setStorage('group_id', '' + ret.data.groupid + '');
//            $api.setStorage('member_type', '' + ret.data.account_type + '');
//            $api.setStorage('user_name', '' + ret.data.username + '');
//            $api.setStorage('nickname', '' + ret.data.username + '');
//            $api.setStorage('company', '' + ret.data.company + '');
//            $api.setStorage('money', '' + ret.data.money + '');
//            $api.setStorage('online', '' + ret.data.online + '');
//            $api.setStorage('message', '' + ret.data.message + '');
//            $api.setStorage('head_pic', '' + ret.data.head_portrait + '');
//            $api.setStorage('chat', '' + ret.data.chat + '');
//            $api.setStorage('credit', '' + ret.data.credit + '');
//            $api.setStorage('collect', '' + ret.data.collect + '');
//            $api.setStorage('rongcloud_token', '' + ret.data.rongcloud_token + '');
//
//
////                账户信息
//            //爱心值//爱心值
//            $api.setStorage("jifen_left", '' + ret.data.extra_count.jifen_left + '');
//            //爱心豆//爱心豆
//            $api.setStorage("jifen_returned", '' + ret.data.extra_count.jifen_returned + '');
//            //总消费//总业绩//商家总业绩
//            $api.setStorage("amount_total", '' + ret.data.extra_count.amount_total + '');
//            //本月分润
//            $api.setStorage("money_thismonth", '' + ret.data.extra_count.jifen_returned + '');
//            //未提货款
//            $api.setStorage("money_unwithdrawn", '' + ret.data.extra_count.money_unwithdrawn + '');
//            //已提货款
//            $api.setStorage("money_withdrawn", '' + ret.data.extra_count.money_withdrawn + '');
//            //总货款//总分润
//            $api.setStorage("money_total", '' + ret.data.extra_count.money_total + '');

            getUserInfo()


            api.sendEvent({
                name: 'reGetMyInfo',
                extra: {
                    key: 'true'
                }
            })
            // api.sendEvent({
            //     name: 'loginSuccess',
            //     extra: {
            //         key: 'true'
            //     }
            // });
            setTimeout(function () {
                api.hideProgress();
                //关闭到指定窗口，最上面显示的窗口到指定name窗口间的所有窗口都会被关闭
                whereToGo(ret.data.account_type,"../")

            }, 1000);
        });

    }
    //获取验证码
    function getVerify(type) {
        var mobile = $api.val($api.byId(type + 'Mobile'));
        //验证手机是否注册过
        var url = 'account/send_verifycode';
        var data = {};
        data['mobile'] = mobile;

        ajaxRequest(url, 'post', data, function (ret, err) {
            if (ret.success) {
                api.toast({
                    msg: "验证码已发送"
                })
                var sendVerify = $api.byId(type + 'SendVerify');
                $api.removeAttr(sendVerify, 'onclick');
                //提交成功前不可更改，防止用发送后用其他号码注册 或者 在服务端验证
                var readonly_mobile = $api.byId(type + 'Mobile');
                $api.attr(readonly_mobile, 'readOnly', 'true');
                $api.html(sendVerify, '已发送(<span id="GetVerify">60</span>)');
                times = 60;
                isinerval = setInterval("CountDown('" + type + "')", 1000);

            }
        });
    }

    function CountDown(type) {
        if (times < 1) {
            //提交成功前不可更改，防止用户发送后用其他号码注册 或者 在服务端验证
            var readonly_mobile = $api.byId(type + 'Mobile');
            $api.removeAttr(readonly_mobile, 'readOnly');
            var sendVerify = $api.byId(type + 'SendVerify');
            $api.attr(sendVerify, 'onclick', 'getVerify("' + type + '")');
            $api.html(sendVerify, '重新获取');
            clearInterval(isinerval);
            return;
        }
        var getVerify = $api.byId('GetVerify');
        $api.html(getVerify, '' + times + '');
        times--;
    }

    //    接收来自win的切换注册类型方法
    function changeType(type) {
        if (type == "member") {
            $("#member").show();
            $("#supplier").hide();
        } else {
            $("#member").hide();
            $("#supplier").show();
        }
    }
</script>
</html>